package com.yimi.yinhepda.views.load_module;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.widget.TextView;

import com.pda.ym.base.BaseActivity;
import com.yimi.yinhepda.db.dao.UnloadScanTableDao;
import com.yimi.yinhepda.entity.LoadTaskEntity;
import com.yimi.yinhepda.entity.response.LoadInfo;
import com.yimi.yinhepda.entity.response.QueryLoadDetailChildBillcode;
import com.yimi.yinhepda.utils.Common;

import java.io.Serializable;
import java.util.Iterator;
import java.util.List;

/**
 * @author 000432
 * @date 2017/4/13
 */
public class LoadBaseActivity extends BaseActivity {
    public TextView num;
    public UnloadScanTableDao mUnloadScanTableDao;
    /**
     * 操作类型，操作码:1 -装车，2- 卸车
     */
    public int operTypeCode = 1;

    @Override
    public String getPageName() {
        return "装车基础界面";
    }

    public LoadBaseActivity(boolean isScan) {
        super(isScan);
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        mUnloadScanTableDao = new UnloadScanTableDao();
    }

    @Override
    protected void onResume() {
        super.onResume();
    }

    /**
     * 查询是否有扫描的单号
     */
    protected boolean isLoadScan(List<LoadInfo> list) {
        Iterator it = list.iterator();
        while (it.hasNext()) {
            LoadInfo billDto = (LoadInfo) it.next();
            if (billDto.getChildList() != null && billDto.getChildList().size() > 0) {
                for (QueryLoadDetailChildBillcode item : billDto.getChildList()) {
                    //查询单号是否扫描
                    if (item.getFlag() == 1) {
                        return true;
                    }
                }
            }
            if (billDto.getWaybillType() != null && billDto.getWaybillType() == 2) {
                return true;
            }
        }
        return false;
    }

    /**
     * 分拨跳转到装卸组界面，否则直接跳转至装车扫描界面
     */
    protected void toLoadUnloadGroupActivity(Context context, List<LoadTaskEntity> entites) {
        Intent intent;

        int deptType = sharedPreferUtil.getIntValue(Common.DEPT_TYPE);
        if (deptType == 5 || deptType == 6) {
            //判断是否是分拨,跳转至装卸组
            intent = new Intent(context, LoadUnloadGroupActivity.class);
        } else {
            intent = new Intent(context, LoadScanActivity.class);
        }
        Bundle bundle = new Bundle();
        bundle.putSerializable("LoadTaskEntites", (Serializable) entites);
        //扫描类型：1-装车扫描，2-卸车扫描
        bundle.putInt("scanType", 1);
        intent.putExtras(bundle);
        startActivity(intent);
        finish();
    }
}
